/**
* @Title: warningDeductionDialog_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEYUWEN001
* @date 2014年11月19日 下午10:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarningDeductionDialogCtrl',
			['$scope','BaseURL','$modalInstance', 'Modal','WarningAddService','WarningScreenService','WarningDeductionService', 
			 function($scope, baseUrl,$modalInstance, Modal,WarningAddService,WarningScreenService,WarningDeductionService){
				$scope.warningScreenService = WarningScreenService;
				$scope.deducitonForm = {};
				$scope.warningData = WarningAddService.warningMarkData;
				$scope.tableDataDeductions = [];
				var targetType = '0'+WarningAddService.mark;//记分对象类型
				var warningMarks = {
						deducitonMedicals:[],//医疗机构
						deducitonStaffs:[],//医护人员
						deducitonInsurs:[],//参保人员
						deductionDeletes:[]//删除过已存库的数据
						};
				if(!WarningAddService.warningMarkData.warningMarks
						|| angular.isUndefined(WarningAddService.warningMarkData.warningMarks)){
					WarningAddService.warningMarkData.warningMarks = [warningMarks];
				}else{
					WarningAddService.warningMarkData.warningMarks = 
						WarningDeductionService.intiWarningMarks(WarningAddService.warningMarkData.warningMarks);
				}
				var pars = {scoreType:'0',scoreLevel:'1',parentId:''};
				var standardScoreParams = function(_mark){
					if(_mark == 1){//机构
						pars.scoreType = '0';//医疗机构
						$scope.codeTemp = '机构编码';
						$scope.nameTemp = '机构名称';
						$scope.isFlat = true;
					}else if(_mark == 2){
						pars.scoreType = '1';//医护人员
						$scope.codeTemp = '医护人员编码';
						$scope.nameTemp = '医护人员名称';
						$scope.isFlat = false;
					}else if(_mark == 3){
						pars.scoreType = '2';//药店人员
						$scope.codeTemp = '机构编码';
						$scope.nameTemp = '机构名称';
//						$scope.codeTemp = '药店编码';
//						$scope.nameTemp = '药店名称';
						$scope.isFlat = true;
					}else if(_mark == 4){
						pars.scoreType = '3';//参保人员
						$scope.codeTemp = '参保人员编码';
						$scope.nameTemp = '参保人员名称';
						$scope.isFlat = true;
					}
					pars.scoreLevel = '1';//评分类型
					return pars;
				}
				var warningAddServiceMark = WarningAddService.mark;
				if(WarningAddService.warningMarkData.orgType){
					if(WarningAddService.mark == 1 
						&& WarningAddService.warningMarkData.orgType == '1'){//orgType：0.机构,1.药店
						warningAddServiceMark = 3;//查药店评分信息
						targetType = '04';//药店
					}else if(WarningAddService.mark == 3){
						warningAddServiceMark = 4;//查参保人评分信息
					}	
				}
				
				//评分类别
				WarningScreenService.getWarningDeduction(standardScoreParams(warningAddServiceMark)).
				success(function(res){
					$scope.ratingCategorys = res.warningDeductions;
					if(res.warningDeductions){
						$scope.markContentValues = res.warningDeductions[0].pointTotal;//该对象总分值
					}
				});
				var pointCuts = [],pointCutTemps = [];//加载已临时扣过的分
				var targetNo = null;
				if(WarningAddService.warningMarkData.caseNo&&!angular.isUndefined(WarningAddService.warningMarkData.caseNo)){
					targetNo = WarningAddService.warningMarkData.code;
				}
				//确保缓存数据集合不为空
				if(!WarningAddService.warningMarkData.warningMarks[0]){
					WarningAddService.warningMarkData.warningMarks = [warningMarks];
				}
				//初始校验值 function(缓存的数据集合,当前对象编号,当前对象类型,展示的数据集合,已入库临时记分信息)
				pointCutTemps = WarningDeductionService.intiParam(WarningAddService.warningMarkData,targetNo,targetType,
						$scope.tableDataDeductions,pointCutTemps);
				//初始化记分数据 function(缓存的数据集合,展示的数据集合,当前对象类型,当前对象类型临时)
				WarningDeductionService.initDeduction(WarningDeductionService.intiWarningMarkData(WarningAddService.warningMarkData),warningMarks,
						$scope.tableDataDeductions,WarningAddService.mark,targetType);
				
				$scope.$watch('deducitonForm.idStandardscore', function(e,v){//监听评分类别
					$scope.deducitonForm.ratingCategory = null;
					$scope.deducitonForm.assessmentContent = null;
					$scope.deducitonForm.assessmentRules = null;
					clearData();
					if($scope.deducitonForm.idStandardscore){
						$scope.onAssessmentContentClick();
					}else{
						$scope.assessmentContents = null;
						$scope.assessmentRules = null;
					}
				});
				$scope.$watch('deducitonForm.pointReal', function(e,v){//监听初始记分
					if(WarningAddService.mark != 2){
						if($scope.deducitonForm.pointReal){
							if(verification()){
								var _pointScores = remainingMaxVal();
								if(_pointScores){
									$scope.deduScores = maxVal($scope.deducitonForm.pointReal);
								}else{
									$scope.deduScores = parseFloat($scope.deducitonForm.pointReal).toFixed(1);
								}
							}
						}else{
							$scope.deduScores = null;
						}
					}
				});
				var clearData = function(){//清除展示值
					$scope.deductionScores = null;
					$scope.deducitonForm.pointReal = null;
					$scope.referenceScores = null;
					$scope.deduScores = null;//记分分值
				}
				$scope.onAssessmentContentClick = function() {
					clearData();
					angular.forEach($scope.ratingCategorys,function(datas,index){
						   if(datas.idStandardscore === $scope.deducitonForm.idStandardscore){
							   if(datas.idStandardscore){
									var par = standardParams(standardScoreParams(warningAddServiceMark).scoreType
											,'2',datas.idStandardscore);//scoreLevel:1.评分类型,2.考核内容，3.考核细则
									WarningScreenService.getWarningDeduction(par).
									success(function(res){
										$scope.assessmentContents = res.warningDeductions;
										if($scope.deducitonForm.idStandardscore){
											angular.forEach($scope.ratingCategorys,function(datas,index){
												   if(datas.idStandardscore === $scope.deducitonForm.idStandardscore){
												   		$scope.deducitonForm.ratingCategory = datas.scoreName;
												   }
											   });
										}
									});
								}
						   }
					   });
				}
				var tableDataDeductionsSum = function(data){//计算分值
					 var pointNum = '0.0';
					 angular.forEach(data,function(datas,index){
							 pointNum = (parseFloat(pointNum) + parseFloat(datas.point)).toFixed(2);
					   });
					return pointNum;
				}
				var remainingMaxVal = function(){//已记分值
					if(WarningAddService.mark != 2){
						if($scope.idStandardscore){
							var _orgContentPoint = parseFloat('0.0');
							if($scope.orgContentPoint){
								if(!$scope.orgContentPointTemp){
									$scope.orgContentPointTemp = '0.0';
								}
								_orgContentPoint = parseFloat($scope.orgContentPoint) + parseFloat($scope.orgContentPointTemp);
							}
							var pointNum = tableDataDeductionsSum($scope.tableDataDeductions);
							return _orgContentPoint +  parseFloat(pointNum);//+ pointNum + pointTempNum;//可记分值
						}
					}else{
						if($scope.idStandardscore){
							var _orgContentPoint = parseFloat('0.0');
							if($scope.orgContentPoint){
								_orgContentPoint = parseFloat($scope.orgContentPoint);
							}
							var pointNum = tableDataDeductionsSum($scope.tableDataDeductions);
							return _orgContentPoint +  parseFloat(pointNum);// + pointTempNum;//可记分值
						}
					}
					return null;
				}
				var maxPointVal = function(pointReal){
					var point = '0.0';//该项可记分值
					if(WarningAddService.mark != 2){
						if(parseFloat(pointReal) >= parseFloat($scope.maxRuleUpperValues)){
							point = $scope.maxRuleUpperValues;
						}else{
							point = pointReal;
						}
					}else{
						if(parseFloat(pointReal) >= parseFloat($scope.markContentValues)){
							point = $scope.maxRuleUpperValues;
						}else{
							point = pointReal;
						}
					}
					return point;
				}
				//校验取分值
				var maxVal = function(pointReal){//当前记分分值
					var point = maxPointVal(pointReal);
					var _scoreVal = remainingMaxVal();//已记分值
					if(_scoreVal){
						if(WarningAddService.mark != 2){
							_scoreVal = parseFloat($scope.maxUpperValues) - _scoreVal//剩余可记分值
						}else{
							_scoreVal = parseFloat($scope.markContentValues) - _scoreVal//剩余可记分值
						}
						if(_scoreVal >= parseFloat(point)){
							return parseFloat(point).toFixed(1);
						}else if(_scoreVal > 0){
							return _scoreVal.toFixed(1);
						}else{
							return '0.0';
						}
					}
					return point;
				}
				var initScores = function(upperValues){//初始化展示记分参数
					if(WarningAddService.mark != 2){
						//初始记分值是否可输入
						if(!$scope.marklowerValues){
							$scope.isDisabled = false;
							$scope.deducitonForm.pointReal = null;
						}else{
							$scope.isDisabled = true;
							$scope.deducitonForm.pointReal = null;
							$scope.deduScores = null;
						}
						var _pointScores = remainingMaxVal();
						if(_pointScores){
							if(_pointScores  >= upperValues){
								if(!$scope.marklowerValues){
									$scope.deducitonForm.pointReal = (upperValues).toFixed(1);
								}
							}else{
								if(!$scope.marklowerValues){
									$scope.isDisabled = null;
									$scope.deducitonForm.pointReal = (upperValues).toFixed(1);
								}
							}
						}else{
							if(!$scope.marklowerValues){
								$scope.deducitonForm.pointReal = (upperValues).toFixed(1);
							}
						}
						$scope.deductionScoreTemps = $scope.deductionScores = upperValues.toFixed(1);
					}else{
						$scope.deducitonForm.pointReal = maxVal(upperValues.toFixed(1));
						$scope.deduScores = maxVal(upperValues.toFixed(1));
						
					}
				}
				var remainingScores = function(data,num){//num:0.减,1.加
					if(num == 0){
							$scope.isFlatTrue = true;//是否操作过记分
							//--记分分值 start--
							if($scope.idStandardscore){
								data.point = maxVal(data.pointReal);
								if(WarningAddService.mark != 2){
									var scores = (parseFloat($scope.markUpperValues) - parseFloat(data.point)).toFixed(1);
									if(parseFloat($scope.markUpperValues) >= parseFloat(data.point)){
										$scope.deductionScoreTemps = $scope.deductionScores = scores;
									}else if(parseFloat($scope.markUpperValues) > 0){
										data.point = $scope.markUpperValues;
										$scope.deductionScoreTemps = $scope.deductionScores = (parseFloat($scope.deductionScoreTemps) - parseFloat(data.point)).toFixed(1);
									}else{
										data.point = '0.0';
										$scope.deductionScoreTemps = $scope.deductionScores = (parseFloat($scope.deductionScoreTemps) - parseFloat(data.point)).toFixed(1);
									}
									data.point = parseFloat(data.point).toFixed(1);
									$scope.deduScores = parseFloat(data.point).toFixed(1);
								}else{
									var scores = (parseFloat($scope.markUpperValues) - parseFloat(data.point)).toFixed(1);
									if(parseFloat($scope.markUpperValues) >= parseFloat(data.point)){
									}else if(parseFloat($scope.markUpperValues) > 0){
										data.point = $scope.markUpperValues;
									}else{
										data.point = '0.0';
									}
									data.point = parseFloat(data.point).toFixed(1);
									$scope.deduScores = parseFloat(data.point).toFixed(1);
								}
							}
							 //--记分分值 end--
					}else if(num == 1){
						$scope.isFlatTrue = true;//是否操作过记分
						if(WarningAddService.mark != 2){
							if($scope.idStandardscore == data.ruleId && data.isFlat){
								var scores = (parseFloat($scope.deductionScoreTemps) + parseFloat(data.point)).toFixed(1);
								if(scores <= parseFloat($scope.markUpperValues)){
									$scope.deductionScoreTemps = $scope.deductionScores = scores;
								}else{
									$scope.deductionScoreTemps = $scope.deductionScores = $scope.markUpperValues;
								}
							}else if($scope.idStandardscore == data.ruleId && !data.isFlat){
								remainingScores(data,null);
							}
						}else{
							data.idStandardscore = $scope.idStandardscore;
							data.upperValues = $scope.markUpperValues;
							remainingScores(data,null);
						}
					}else if(data.upperValues){//初始化记分项数据
						if(WarningAddService.mark != 2){
							if($scope.idStandardscore == data.idStandardscore){
								initScores(parseFloat($scope.markUpperValues));
							}else{
								$scope.idStandardscore = data.idStandardscore;
								$scope.markUpperValues = data.upperValues;
								initScores(parseFloat(data.upperValues));
							}
						}else{
							if($scope.idStandardscore == data.idStandardscore){
								initScores(parseFloat(maxVal(data.upperValues)));
							}else{
								$scope.idStandardscore = data.idStandardscore;
								$scope.markUpperValues = data.upperValues;
								initScores(parseFloat(data.upperValues));
							}
						}
					}
				}
				$scope.onAssessmentRulesItemClick = function(data) {//选中考核内容项
					clearData();
					if(WarningAddService.mark != 2){
						$scope.maxUpperRuleId = data.idStandardscore;
						$scope.maxUpperValues = data.upperValues;
					}else{
						$scope.maxRuleId = data.idStandardscore;
						$scope.maxRuleUpperValues = data.upperValues;
					}
					if(data.idStandardscore){
						var par = standardParams(standardScoreParams(warningAddServiceMark).scoreType
								,'3',data.idStandardscore);//scoreLevel:1.评分类型,2.考核内容，3.考核细则
						if(WarningAddService.mark != 2){
							par.idStandardscore = data.idStandardscore;
						}else{
							par.idStandardscore = null;
						}
						WarningScreenService.getWarningDeduction(par).
						success(function(res){
							if(WarningAddService.mark != 2){
								if(res.warningDeductions){
									angular.forEach(res.warningDeductions,function(datas,index){
										if(index == 0){
											   $scope.orgContentPoint = datas.orgContentPoint;//考核内容已记分值
										}
									});
								}
							}
							if(WarningAddService.mark != 2){
								$scope.assessmentRules = res.warningDeductions;
							}
							if($scope.assessmentContents){
								angular.forEach($scope.assessmentContents,function(datas,index){
									   if(datas.idStandardscore === data.idStandardscore){
										   if(WarningAddService.mark == 2){
											   $scope.deducitonForm.id = data.idStandardscore;
											   if(datas.idStandardscore){
												   $scope.deductionScores = '0.0';
												   WarningScreenService.getPointScose({targetNo:WarningAddService.warningMarkData.code}).
													success(function(res){
														if(res.pointScose){
															$scope.orgContentPoint = res.pointScose;//考核内容已记分值
															$scope.deductionScores = parseFloat(res.pointScose).toFixed(1);
														}else{
															$scope.orgContentPoint = null;
														}
														remainingScores(datas,null);
													});
											   }
										   }
									   		$scope.deducitonForm.assessmentContent = datas.scoreName;
										   data.selected = true;//datas.selected == true;//?false:true;
									   }else{
										   datas.selected = false;
									   }
								   });
							}
						});
					}
				}
				//刷新记分数据
				var findIdStandardScores = function(data){
					 WarningScreenService.getFindIdStandardScores({idStandardscore:$scope.maxUpperRuleId}).
					 	success(function(res){
							if(res.standardscores){
								var num = '0.0';
								angular.forEach($scope.tableDataDeductions,function(datasDedu,index){
									angular.forEach(res.standardscores,function(datas,index){
										if(datasDedu.ruleId === datas.idStandardscore){
											 num = (parseFloat(num) +parseFloat(datasDedu.point)).toFixed(2);
										}
									});
								});
								 $scope.orgContentPointTemp = parseFloat(num).toFixed(1);//考核内容已记分值
								if(data && WarningAddService.mark != 2){
									remainingScores(data);//剩余分值
								}
							}else{
								if(data && WarningAddService.mark != 2){
									remainingScores(data);//剩余分值
								}
							}
						});
				}
				
				$scope.onItemClick = function(data) {//选中考核细则项
					if(WarningAddService.mark != 2){
						$scope.deducitonForm.pointReal = null;
						 $scope.maxRuleId = data.idStandardscore;
						 $scope.marklowerValues = data.lowerValues;
						 $scope.maxRuleUpperValues = data.upperValues;
						 $scope.referenceScores = data.referenceScores;
						 findIdStandardScores(data);//刷新记分数据
						 if($scope.assessmentRules){
								angular.forEach($scope.assessmentRules,function(datas,index){
									   if(datas.idStandardscore === data.idStandardscore){
										   if(WarningAddService.mark != '2'){
											   $scope.deducitonForm.id = data.idStandardscore;
										   }
										   $scope.deducitonForm.id = data.idStandardscore;
									   		$scope.deducitonForm.assessmentRules = datas.scoreName;
										   data.selected = true;
									   }else{
										   datas.selected = false;
									   }
								   });
							}
					 }
				}
				var standardParams = function(_scoreType,_scoreLevel,_parentId){
						var parTemp = [];
						pars.scoreType = _scoreType;//医疗机构
						pars.scoreLevel = _scoreLevel;//评分类型
						pars.parentId = _parentId;//评分parentId
						return pars;
				}
				
				//支持初始记分项数据动态变动
				var tempScores = function(num,par){//num:0.减,1.加
					remainingScores(par,num);
				}
				
				var delScose = function(dataTemp,indexTemp){
					$scope.tableDataDeductions.splice(indexTemp-1,1);
					 tempScores(1,dataTemp);//支持初始记分项数据动态变动
					 return true;
				}
				//记分
				$scope.marking = function(){
					var par = params();
					if(WarningAddService.mark != 2){
						if(verifyLower(par.pointReal,$scope.marklowerValues) || parseFloat(par.pointReal) <= 0){
							Modal.alert("该初始记分必须在参考分值区间之内且初始记分大于"+$scope.marklowerValues+"！");
							$scope.deducitonForm.pointReal = null;
							return null;
						}
					}
					var num = 0;
					var count = 0;
					var strMsgPoint ='';
					if(verification()){
						var dataTemp = null;
						var indexTemp = null;
							angular.forEach($scope.tableDataDeductions,function(data,index){
								   if(data.ruleId === par.ruleId && data.isFlat 
										   && WarningAddService.warningMarkData.code === data.targetNo){
										if(WarningAddService.mark != 2){
											if(!$scope.marklowerValues){//固定分值
												strMsgPoint = '该项考核细则已记分！';
												count++;
											}else{
												dataTemp = data;
												indexTemp = index + 1;
											}
										}else{
											strMsgPoint = '该项考核内容已记分！';
											count++;
										}
								   }
							   });
							if(dataTemp && indexTemp){
								Modal.confirm('该项细则已扣'+dataTemp.point+'分,'+'是否替换成'+par.pointReal+'分?',function(){
									if(delScose(dataTemp,indexTemp)){
										tempScores(0,par);//支持初始记分项数据动态变动
										$scope.tableDataDeductions.push(par);
									}
								});
							}else if(count == 0){
								tempScores(0,par);//支持初始记分项数据动态变动
								$scope.tableDataDeductions.push(par);
							}else{
								Modal.alert(strMsgPoint);
							}
					}
				}
				var params = function (){//组装参数
					var ratingCategory=null;
					if($scope.deducitonForm.ratingCategory&&!angular.isUndefined($scope.deducitonForm.ratingCategory)){
						ratingCategory = $scope.deducitonForm.ratingCategory;
					}
					var assessmentContent=null;
					if($scope.deducitonForm.assessmentContent&&!angular.isUndefined($scope.deducitonForm.assessmentContent)){
						assessmentContent = $scope.deducitonForm.assessmentContent;
					}
					var assessmentRules=null;
					if($scope.deducitonForm.assessmentRules&&!angular.isUndefined($scope.deducitonForm.assessmentRules)){
						assessmentRules = $scope.deducitonForm.assessmentRules;
					}
					if(WarningAddService.mark == 2){
						assessmentRules = assessmentContent;
					}
					var pointReal=null;
					if($scope.deducitonForm.pointReal&&!angular.isUndefined($scope.deducitonForm.pointReal)){
						pointReal = parseFloat($scope.deducitonForm.pointReal).toFixed(1);
					}
					var point = '0.0';
					var ruleId = $scope.deducitonForm.id;
					var reason = assessmentRules;
					var happenDate = null,punishDateStart = null,punishDateEnd = null;
					if(WarningAddService.warningMarkData.caseType == '01'){
						happenDate = WarningAddService.warningMarkData.punishDateEnd;//案发时间
					}else{
						happenDate = WarningAddService.warningMarkData.punishDateEnd;//案发时间
					}
					var params = {
							ratingCategory:ratingCategory,
							assessmentContent:assessmentContent,
							assessmentRules:assessmentRules,
							caseType:WarningAddService.warningMarkData.caseType,// 案件类型
							caseNo:WarningAddService.warningMarkData.caseNo,// 案件编号
							targetType:targetType,// 记分对象类型(01医疗机构、02医生、03参保人、04药店)
							targetNo:WarningAddService.warningMarkData.code,// 记分对象编号
							orgCode:WarningAddService.warningMarkData.medicalCode,// 机构编号
							point:point,// 记分值
							pointReal:pointReal,// 实际记分值
							ruleId:ruleId,// 记分规则
							reason:reason,// 记分原因
							happenDate:happenDate,// 案发日期
							punishDateStart:punishDateStart,// 惩罚起期
							punishDateEnd:punishDateEnd,// 惩罚终期
							isFlat:true//新增记分
					}
					return params;
				}
				var verifyLower = function(pointReal,marklowerValues){
					if(marklowerValues){
						return parseFloat(pointReal) < parseFloat(marklowerValues);
					}
					return false;
				}
				var verification = function(){//校验
					var par = params();
					if(!par.ratingCategory){
						Modal.alert("评分类别不能为空！");
						return null;
					}
					if(!par.assessmentContent){
						Modal.alert("考核内容为必选项！");
						return null;
					}
					if(!par.assessmentRules && WarningAddService.mark != 2){//医务人员没有评分细则
						Modal.alert("考核细则为必选项！");
						return null;
					}
					if(!/^[\d]*[.]?[\d]?$/.test(par.pointReal)){
						Modal.alert("该初始记分必须为数字或一位小数值！");
						$scope.deducitonForm.pointReal = null;
						return null;
					}else if(WarningAddService.mark != 2 && (parseFloat(par.pointReal) > parseFloat($scope.markUpperValues) || par.pointReal.length > 6)){
						Modal.alert("该初始记分必须在参考分值区间之内且初始记分大于"+$scope.marklowerValues+"！");
						$scope.deducitonForm.pointReal = null;
						return null;
					}
				     return true;
				}
				$scope.deleteDeduction = function(ruleId,idPointCut){//删除
					Modal.confirm("确认删除?",function(){
						if(!$scope.tableDataDeductions){
							return;
						}
						angular.forEach($scope.tableDataDeductions,function(data,index){
							var ids = {idPointCut:idPointCut,remainingScores:data.point,caseType:'',caseNo:''};
							//组装删除数据 function(临时集合,当前操作对象,当前数据,当前操作记录评分标准id,已存临时表评分标准id)
							warningMarks = WarningDeductionService.delWarningMarks(warningMarks,WarningAddService.mark,data,ruleId,idPointCut);
							if(data.ruleId === ruleId && (data.isFlat || data.storageIsTrue) && !idPointCut){
							 if(warningMarks.deductionDeletes){
								 angular.forEach(warningMarks.deductionDeletes,function(datas,indexDel){
										if(datas.ruleId === ruleId && (datas.isFlat || data.storageIsTrue)
												&& WarningAddService.warningMarkData.caseType == datas.caseType 
												   && WarningAddService.warningMarkData.caseNo === datas.caseNo){
											warningMarks.deductionDeletes.splice(indexDel,1);
										}
									   });
								 if(data.storageIsTrue){//暂存记分删除标记
									 data.isFlat = true;//设为true:为暂存删除信息
								 }
							 	warningMarks.deductionDeletes.push(data);//删除已存库数据
							 }
							   $scope.tableDataDeductions.splice(index,1);
							   tempScores(1,data);//支持初始记分项数据动态变动
							   findIdStandardScores(data);//刷新记分数据
						   }
						   if(data.ruleId === ruleId && !data.isFlat && idPointCut === data.idPointCut
								   && !data.storageIsTrue){
							   ids.caseType = data.caseType;
							   ids.caseNo = data.caseNo;
							   if(warningMarks.deductionDeletes && WarningAddService.warningMarkData.caseType == data.caseType 
									   && WarningAddService.warningMarkData.caseNo === data.caseNo){
								   warningMarks.deductionDeletes.push(ids);//删除已存库数据
								 }
							   $scope.tableDataDeductions.splice(index,1);
							   tempScores(1,data);//支持初始记分项数据动态变动
							   findIdStandardScores(data);//刷新记分数据
						   }
					   });
					});
				}
				//保存
				$scope.confirm = function (){
					if(!$scope.isFlatTrue){
						Modal.alert("尚未操作记分！");
						return null;
					}
					if(WarningDeductionService.deleteFunction(pointCutTemps,$scope.tableDataDeductions)){
						//替换数据
						if(warningMarkFunction()){
							$scope.isFlatTrue = null;
							WarningAddService.warningMarks = [];
							WarningAddService.warningMarks.push(warningMarks);
							$modalInstance.close(WarningAddService.warningMarks);
						}
					}
				}
				//先拆数据进行封装
				var warningMarkFunction = function(){
					//function(当前节点数据原型,临时数据集合,目标对象,当前展示的集合)
					warningMarks = WarningDeductionService.warningMarkFunction(WarningAddService.warningMarkData,warningMarks,
							WarningAddService.mark,$scope.tableDataDeductions);
					return true;
				}
				$scope.onClose = function(){//关闭弹框
    	    		$modalInstance.dismiss();
    	    	}
	}]);
})();